package tools.chapter24;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @author Kevin
 * @date 2020/4/14 0:03
 */
public class afterClass {
    Executor ex;
    PurchersOrder po;

    afterClass(Executor ex, PurchersOrder po) {
        this.ex = ex;
        this.po = po;
    }

    public Boolean valid() {
        CompletableFuture<Boolean> cf =
                CompletableFuture.supplyAsync(()->{
                    //在数据库中查询规则
                    return findRuleByJdbc();
                },ex).thenApply(r -> {
                    //规则校验
                    return check(po, r);
                });
        Boolean isOk = cf.join();
        return isOk;
    }

    class PurchersOrder{}
    String findRuleByJdbc() {return "The rule of JDBC.";}
    Boolean check(PurchersOrder po, String rule){return true;}
}
